package com.george.common.api.feign.fallBack.user;

import com.george.common.api.feign.user.UserServiceFeign;
import com.george.common.entity.dto.user.ScbUserDTO;
import com.george.common.exception.BaseException;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Create By George on /2023/4/10
 * description: 用户Feign服务降级实现
 *
 * @author George
 */
@Slf4j
@Component
public class UserServiceFeignFallBack implements FallbackFactory<UserServiceFeign> {

    /**
     * Returns an instance of the fallback appropriate for the given cause
     */
    @Override
    public UserServiceFeign create(Throwable cause) {
        return new UserServiceFeign() {

            /**
             * 根据用户id获取用户信息
             *
             * @param userId
             * @return void
             * @author George
             * @date 2023/4/10 1:14
             */
            @Override
            public ScbUserDTO getUserInfoById(Long userId) {
                log.error("UserServiceFeign: getUserInfoById fail reason was: {}", cause.getMessage());
                throw new BaseException("获取用户信息失败，用户服务接口降级返回");
            }

            /**
             * 根据用户名称获取用户信息
             *
             * @param name
             * @return void
             * @author George
             * @date 2023/4/10 1:14
             */
            @Override
            public ScbUserDTO getUserInfoByName(String name) {
                log.error("UserServiceFeign: getUserInfoByName fail reason was: {}", cause.getMessage());
                throw new BaseException("获取用户信息失败，用户服务接口降级返回");
            }

            /**
             *  根据登录用户名称获取用户信息
             * @author George
             * @date 2023/7/11 17:43
             * @param name
             * @return com.george.common.entity.dto.user.ScbUserDTO
             */
            @Override
            public ScbUserDTO getUserInfoByUsername(String name) {
                log.error("UserServiceFeign: getUserInfoByUsername fail reason was: {}", cause.getMessage());
                throw new BaseException("获取用户信息失败，用户服务接口降级返回");
            }
        };
    }
}
